/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code2 {
    public boolean isSymmetric(TreeNode root) {
        return dfs(root.left,root.right);
    }

    public boolean dfs(TreeNode L,TreeNode R) {
        //都为null
        if(L == null && R == null) {
            return true;
        } else if(L == null || R == null) {
            //一个为null
            return false;
        } else if(L.val != R.val) {
            //都不为null，但是不相等
            return false;
        }

        return dfs(L.left,R.right)&&dfs(L.right,R.left);
    }
}